<style type="text/css">
    th.title {
    	width: 268px;
    }
    .form-inline {
    	margin-bottom: 10px;
    }
</style>
<script type="text/javascript">
    function deleteStock(id, obj) {
        if (confirm('确认删除?')) {
            $.ajax({
                type: "get",
                url: "/stock/delete?id="+id,
                data: {},    
                success: function(data) {
                    switch(data) {	
                        case "1":$(obj).parent().parent().remove();break;
	        			default:alert('删除失败');
	        		}
	        	}			
	        });
        }
    }
    function printBarcode(sku){
        window.open("/stock/print?sku="+sku,"打印"+sku,"scrollbars=yes, resizable=yes,width=1200,screenX=200");
    }
</script>
<div class="pageheader">
	<h2>
		<i class="fa fa-inbox"></i>库存管理
	</h2>
	<div class="breadcrumb-wrapper">
		<span class="label">你所在的位置：</span>
		<ol class="breadcrumb">
			<li><a href="/index">ERP管理系统</a></li>
			<li>库存管理</li>
			<li class="active">库存列表</li>
		</ol>
	</div>
</div>
<div class="contentpanel">
<div class="main">
	<form class="form-inline" method="post" action="/stock">
		<div class="form-group">
		    <input type="text" value="<?php echo $this->sku;?>" class="form-control" name="sku" placeholder="SKU">
		</div>
		<div class="form-group">
			<input type="text" value="<?php echo $this->title;?>" class="form-control" name="title" placeholder="产品名称">
		</div>
        <!-- <div class="form-group">
            <label for="Site">英文标题</label>
            <select class='form-control' name='has_en'>
                <option value=''>选择</option>
                <option value='1' <?php if($this->has_en == '1'){echo 'selected="selected"';}?>>无</option>
		        <option value='2' <?php if($this->has_en == '2'){echo 'selected="selected"';}?>>有</option>
	    	</select>
        </div> -->
		<button type="submit" class="btn btn-primary">搜索</button>
    </form>
    <div class="form-group">
        <?php if(!empty($this->totalStockStr)):?>
        <div class="alert alert-info"><?php echo $this->totalStockStr;?></div>
        <?php endif;?>
    </div>
	<div class="table-responsive">
		<table class="table table-bordered table-hover">
			<thead>
				<tr>
					<th>编号</th>
					<th>SKU</th>
					<th class="title">产品名称</th>
					<th>尺码</th>
					<th>永不下架</th>
					<th>添加时间</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
                <?php if ($this->stockList):?>
                <?php foreach ($this->stockList as $v):?>
                <tr>
					<th scope="row"><?php echo $v['stock_id'];?></th>
					<td><?php echo $v['sku'];?></td>
					<td><?php echo $v['title'];?><br/><?php echo $v['en_title'];?></td>
					<td>
                        <?php 
                        echo "<div>";
                        foreach ( $v ['stock'] as $_v ) {
                    	    echo "<span>";
                    	    echo '尺码: ' . $_v ['size'] . ', 理论库存: ' . $_v ['value'].',实际库存：'.$_v['t_value'];
                    	    if ($_v ['t_value'] < $_v ['warning_value']) {
                    		    echo ', <span class="text-danger">低于警告值：' . $_v ['warning_value'] . '</span>';
		                    }
		                    echo "</span>";
		                    echo '<br/>';
                        }
                        echo "</div>";
                        ?>
                        <input style='float: right;' type="button" class="btn btn-default btn-sm" value="打印" onclick="printBarcode('<?php echo $_v['sku'];?>');">
					</td>
					<td><?php echo $v['is_forlong'] ? '是' : '否';?></td>
					<td><?php echo $v['add_time']; ?></td>
					<td>
				        <a class="btn btn-default btn-sm" title="修改库存" href="/stock/update?id=<?php echo $v['stock_id'];?>">修改</a> 
				        <a class="btn btn-default btn-sm" title="删除库存" href="javascript:void(0);" onclick="deleteStock(<?php echo $v['stock_id']; ?>, this)">删除</a>
				        <a class="btn btn-default btn-sm" title="增减库存" href="/stock/addnum?id=<?php echo $v['stock_id'];?>">增减</a> 
				        <a class="btn btn-default btn-sm" title="特殊问题管理" href="/stock/specialmanage?id=<?php echo $v['stock_id'];?>">特殊</a>
					</td>
				</tr>
			    <?php endforeach;?> 
			    <?php endif;?>
			    <tr>
					<td colspan="7">
			            <?php echo $this->paginationControl ( $this->paginator, 'Sliding', 'page/pager.phtml', array ('title' => $this->title,'has_en'=>$this->has_en) );?>
			        </td>
				</tr>
			</tbody>
		</table>
	</div>
</div>
</div>
